package com.azusa.common.http;

import java.util.HashMap;
import java.util.Map;
/**
 * 
 * <p>类功能说明:http请求，封装和初始化了一些请求http的必要参数和属性。请求中除url不能为空外，其他属性可以根据需求设置或者默认。</p>
 * <p>Class Function Description:</p>
 * <p>Title: HttpRequest.java</p> 
 * <p>Description:Azusa</p>
 * <p>Copyright: Copyright © 2013 Leonard Lan.All Rights Reserved.</p>
 * <p>Company:Azusa</p>
 * @author Leonard Lan
   @date Aug 27, 2013 10:43:41 AM
 * @version v1.0
 * @since azusa-commons v1.0.0
 */
public class HttpRequest {
	/**请求的URL地址*/
	private String url;
	
	/**对HTTP请求设置自定义的请求头*/
	private Map<String, String> headers = new HashMap<String,String>();
	
	/** HTTP请求参数*/
	private Map<String, String> parameters = new HashMap<String,String>();
	
	/** 连接超时时间 */
	private int connectionTimeout = 5000;
	
	/** 读超时时间 */
	private int readTimeout = 60000;
	
	/**设置编码方式，发送请求和接收返回结果都将使用的编码方式，默认为UTF-8*/
	private String charset = "UTF-8";
	
	/** 代理 */
	private String agent = "Azusa/1.0";
	
	public HttpRequest(){
		initCommonHeader();
	}

	/**
	 * 初始化一些常用的Header属性
	 * */
	protected void initCommonHeader(){
		headers.put("Content-Type", "application/x-www-form-urlencoded;charset=" + this.charset);
		headers.put("Accept", "text/xml,text/javascript,text/html, application/xhtml+xml, */*");
		headers.put("User-Agent", this.agent);
	}
	
	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public Map<String, String> getHeaders() {
		return headers;
	}

	public void setHeaders(Map<String, String> headers) {
		this.headers = headers;
	}

	public Map<String, String> getParameters() {
		return parameters;
	}

	public void setParameters(Map<String, String> parameters) {
		this.parameters = parameters;
	}

	public int getConnectionTimeout() {
		return connectionTimeout;
	}

	public void setConnectionTimeout(int connectionTimeout) {
		this.connectionTimeout = connectionTimeout;
	}

	public int getReadTimeout() {
		return readTimeout;
	}

	public void setReadTimeout(int readTimeout) {
		this.readTimeout = readTimeout;
	}

	public String getCharset() {
		return charset;
	}

	public void setCharset(String charset) {
		this.charset = charset;
	}
}
